/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cube;

/**
 * @author charmgil
 */


import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.animation.Timeline;
import javafx.animation.Interpolator;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.Group;

/**
 * @author charmgil
 */

// Tkaen from a code of Raghu Nair
public class FaceLabel extends CustomNode{

    // text
    public var labeltext: String;
    public var show: Boolean = false;

    /* Width */
    public-init var width :Integer = 90;
    public-init var height :Integer = 32;

    var x = bind Layout.offsetX + Layout.obW / 2; // - width / 2;
    var y = bind Layout.offsetY + ( 20 + Layout.obH ) / 2;

    var glowColor = Color.TRANSPARENT;
    override var opacity = 0.0;
    public def showTip:Timeline = Timeline {
        keyFrames: [
            at (0s) {
                glowColor => Color.TRANSPARENT;
            opacity => 0.0;
            },
            at (1s) {
                glowColor => Color.color(0.5, 0.5, 0.5, 0.5);
                opacity => 1.0 tween Interpolator.EASEBOTH;
            },
        ]
    }

    var rectangle:Rectangle = Rectangle{
        x: bind x - 7
        y: bind y

        width: bind text.layoutBounds.width + 20
        arcWidth: 10
        arcHeight: 10

        height:height

        fill:Color.BLACK
        opacity: 75

        visible: bind show
    }

    var text:Text = Text {
        //translateX: bind (rectangle.translateX )
        //translateY: bind rectangle.translateY+(rectangle.layoutBounds.height / 2) + 3

        x: bind x + 3
        y: bind y + ( rectangle.layoutBounds.height / 2 ) + 7

        font: Font {
            size: 22
        }
        fill: Color.WHITE
        opacity: 75
        content: bind labeltext

        visible: bind show
    }

    override function create():Node {
        Group{
            content: [ rectangle, text ]
       }

    }

//        sourceNode.opacity = 1.0;
//            showTip.rate = 1.0;
//            showTip.playFromStart();
//            println( "tt" );
}

